package davey.wu.hamcrest.expected;

import org.hamcrest.Matcher;
import org.hamcrest.beans.HasProperty;
import org.hamcrest.beans.HasPropertyWithValue;
import org.hamcrest.core.IsEqual;
import davey.wu.hamcrest.expected.interdef.EntityExpectedOp;

public class EntityExpected<T> extends BaseImplExpected<T, EntityExpectedOp<T>> implements EntityExpectedOp<T> {

	@SuppressWarnings("unchecked")
	public EntityExpected(Class<T> clazT, Class<EntityExpectedOp> clazE) {
		super(clazT, clazE);
	}

	@Override
	protected EntityExpected<T> getInstance() {
		return new EntityExpected<T>(this.clazT, EntityExpectedOp.class);
	}

	public EntityExpectedOp<T> hasProperty(String name) {
		Matcher<T> matcher = HasProperty.hasProperty(name);
		return super.link(matcher);
	}

	public EntityExpectedOp<T> hasProperty(String name, Object value) {
		if (value == null) {
			return this.nullProperty(name);
		}
		IsEqual<Object> matcher = new IsEqual<Object>(value);
		Matcher<T> _matcher = HasPropertyWithValue.hasProperty(name, matcher);
		return super.link(_matcher);
	}

	public EntityExpectedOp<T> hasProperty(String name, Matcher<?> matcher) {
		if (matcher == null) {
			return this.nullProperty(name);
		}
		Matcher<T> _matcher = HasPropertyWithValue.hasProperty(name, matcher);
		return super.link(_matcher);
	}

	private EntityExpectedOp<T> nullProperty(String name) {
		IsEqual<Object> matcher = new IsEqual<Object>(null);
		Matcher<T> _matcher = HasPropertyWithValue.hasProperty(name, matcher);
		return super.link(_matcher);
	}
}
